<?php
//Connection statement
require_once('../Connections/cn.php');

// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("csvfile", true, "", "", "", "", "");
$tNGs->prepareValidation($formValidation);
// End trigger

// Make an CVS Import transaction instance
$csv_tempo = new tNG_CSVImport($cn);
$tNGs->addTransaction($csv_tempo);
// Register triggers
$csv_tempo->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$csv_tempo->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
// Add columns
$csv_tempo->setTable("tempo");
$csv_tempo->addColumn("rut_persona_temp", "STRING_TYPE", "CSV", "1");
$csv_tempo->addColumn("codigo_ciudad_temp", "NUMERIC_TYPE", "CSV", "2");
$csv_tempo->addColumn("nombre_persona_temp", "STRING_TYPE", "CSV", "3");
$csv_tempo->addColumn("paterno_persona_temp", "STRING_TYPE", "CSV", "4");
$csv_tempo->addColumn("materno_persona_temp", "STRING_TYPE", "CSV", "5");
$csv_tempo->addColumn("fechanac_persona_temp", "DATE_TYPE", "CSV", "6");
$csv_tempo->addColumn("direccion_persona_temp", "STRING_TYPE", "CSV", "7");
$csv_tempo->addColumn("email_persona_temp", "STRING_TYPE", "CSV", "8");
$csv_tempo->addColumn("credencial_persona_temp", "STRING_TYPE", "CSV", "9");
$csv_tempo->addColumn("ann_ingreso_temp", "NUMERIC_TYPE", "CSV", "10");
$csv_tempo->addColumn("regular_alumno_temp", "NUMERIC_TYPE", "CSV", "12");
$csv_tempo->addColumn("ano_matricula_temp", "NUMERIC_TYPE", "CSV", "13");
$csv_tempo->addColumn("semestre_matricula_temp", "NUMERIC_TYPE", "CSV", "14");
$csv_tempo->addColumn("nivel_matricula_temp", "NUMERIC_TYPE", "CSV", "15");
$csv_tempo->addColumn("tesista_matricula_temp", "NUMERIC_TYPE", "CSV", "16");
$csv_tempo->addColumn("numero_matricula_temp", "STRING_TYPE", "CSV", "17");
$csv_tempo->addColumn("codigo_carrera_temp", "STRING_TYPE", "CSV", "18");
$csv_tempo->addColumn("jornada_matricula_temp", "NUMERIC_TYPE", "CSV", "19");
$csv_tempo->setPrimaryKey("rut_persona_temp", "STRING_TYPE");
$csv_tempo->setSource("FILES", "csvfile");
$csv_tempo->setHeader(false);
$csv_tempo->setDelimiter(",");
$csv_tempo->setEnclosure("\"");
$csv_tempo->setHandleDuplicates("update"); 
$csv_tempo->setCSVUniqueKey("rut_persona_temp");

// Execute all the registered transactions
$tNGs->executeTransactions();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.6.0?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
</head>

<body>
<?php
	echo  $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" enctype="multipart/form-data">
  <table cellpadding="2" cellspacing="0" class="KT_tngtable">
    <tr>
      <td class="KT_th"><label for="csvfile">CSV File:</label></td>
      <td><input type="file" name="csvfile" id="csvfile" size="32" />
      </td>
    </tr>
    <tr class="KT_buttons">
      <td colspan="2"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Import" />
      </td>
    </tr>
  </table>
</form>
<p>
  <?php
	echo $csv_tempo->getHints(); //aqui se encuentra la tabla de ejemplo que se muestra para llenar con el csv
?>
</p>
<?php
	echo $tNGs->getErrorMsg();
?></body>
</html>
